package module.main
{
	import com.darwin.darwinDll.Dll;
	
	import flash.utils.Dictionary;

	public class MainConfig
	{
		public function MainConfig()
		{
		}
		
		//声望////////////////////////////////////////////////////////////////////
		private static function get prestigeConfigArr():Array{
			return Dll.getInstance().getSynPreloadRes("prestige") as Array;
		}
		
		private static var _prestigeConfigDic:Dictionary;
		private static function get prestigeConfigDic():Dictionary{
			if(!MainConfig._prestigeConfigDic){
				MainConfig._prestigeConfigDic = new Dictionary;
				var len:int = prestigeConfigArr.length;
				for(var i:int=0;i<len;i++){
					MainConfig._prestigeConfigDic[prestigeConfigArr[i].level] = prestigeConfigArr[i].prestige;
				}
			}
			return _prestigeConfigDic;
		}
		/**
		 * 根据等级获取该等级所需声望 
		 * @return 
		 * 
		 */
		public static function getPrestigeForLevel(level:int):int{
			return int(prestigeConfigDic[level]);
		} 
		/**
		 * 根据当前声望获取当前等级
		 * @return 
		 * 
		 */
		public static function getLevelForPrestige(prestige:int):int{
			var level:int = 0;
			var len:int = prestigeConfigArr.length;
			for(var i:int=0;i<len;i++){
				if(prestigeConfigArr[i].prestige<=prestige){
					level = prestigeConfigArr[i].level;
				}
			}
			return level;
		} 
		/**
		 * 根据当前声望获取下一等级
		 * @return 
		 * 
		 */
		public static function getNextLevelForPrestige(prestige:int):int{
			return getLevelForPrestige(prestige)+1;
		} 
		/**
		 * 根据当前声望获取下一等级所需声望
		 * @return 
		 * 
		 */
		public static function getNextLevelPrestige(prestige:int):int{
			var curLevel:int = getLevelForPrestige(prestige);
			var nextPrestige:int = prestigeConfigDic[curLevel+1];
			return nextPrestige;
		}
		/**
		 * 距离下一级还差多少声望
		 * @param prestige
		 * @return 
		 * 
		 */
		public static function getNextDiffPrestige(prestige:int):int{
			return getNextLevelPrestige(prestige) - prestige;
		}
		
		
		//繁荣度////////////////////////////////////////////////////////////////////
		private static function get prosperityConfigArr():Array{
			return Dll.getInstance().getSynPreloadRes("prosperity") as Array;
		}
		
		private static var _prosperityConfigDic:Dictionary;
		private static function get prosperityConfigDic():Dictionary{
			if(!MainConfig._prosperityConfigDic){
				MainConfig._prosperityConfigDic = new Dictionary;
				var len:int = prosperityConfigArr.length;
				for(var i:int=0;i<len;i++){
					MainConfig._prosperityConfigDic[prosperityConfigArr[i].level] = prosperityConfigArr[i].prosperity;
				}
			}
			return _prosperityConfigDic;
		}
		/**
		 * 根据等级获取该等级所需繁荣度 
		 * @return 
		 * 
		 */
		public static function getProsperityForLevel(level:int):int{
			return int(prosperityConfigDic[level]);
		} 
		/**
		 * 根据当前繁荣度获取当前等级
		 * @return 
		 * 
		 */
		public static function getLevelForProsperity(prosperity:int):int{
			var level:int = 0;
			var len:int = prosperityConfigArr.length;
			for(var i:int=0;i<len;i++){
				if(prosperityConfigArr[i].prosperity<=prosperity){
					level = prosperityConfigArr[i].level;
				}
			}
			return level;
		} 
		/**
		 * 根据当前繁荣度获取下一等级
		 * @return 
		 * 
		 */
		public static function getNextLevelForProsperity(prosperity:int):int{
			return getLevelForProsperity(prosperity)+1;
		}  
		/**
		 * 根据当前繁荣度获取下一等级所需繁荣度
		 * @return 
		 * 
		 */
		public static function getNextLevelProsperity(prosperity:int):int{
			var curLevel:int = getLevelForProsperity(prosperity);
			var nextProsperity:int = prosperityConfigDic[curLevel+1];
			return nextProsperity;
		} 
		/**
		 * 距离下一级还差多少繁荣度
		 * @param prosperity
		 * @return 
		 * 
		 */
		public static function getNextDiffProsperity(prosperity:int):int{
			return getNextLevelProsperity(prosperity) - prosperity;
		}
		

		
		
		
		//资源上限////////////////////////////////////////////////////////////////////
		private static function get resourceLimitConfigArr():Array{
			return Dll.getInstance().getSynPreloadRes("resourceLimit") as Array;
		}
		/**
		 * 获取当前领地等级所对应的资源上限
		 * @param prosperityLevel	领地等级
		 * @param resourceType		资源类型 (MainConst.FOOD/MainConst.WOOD...)
		 * @return 
		 * 
		 */
		public static function getResourceLimit(prosperityLevel:int,resourceType:String):int{
			return int(resourceLimitConfigArr[prosperityLevel][resourceType]);
		}
	}
}